/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : Ammeter.hpp
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2023.11.23
  -	Brief         : Ammeter function
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *  2023.11.23        liuzhihua                  Create file          
***/

#ifndef AMMETER_HPP
#define AMMETER_HPP

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "main.h"
#include "iMath.h"
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/


class Ammeter 
{
    public:
        static const double VOLTAGE_GAIN; //external gain
        static const float SR[4];//Sampling Resistors
        enum {
            SamplingResistor20 = 0,
            SamplingResistor0d1 = 1,
            SamplingResistor0d02 = 2,
            SamplingResistor0d004 = 3,
        };

        typedef enum {
            GEAR_1000UA = 0,
            GEAR_200MA = 1,
            GEAR_1A = 2,
            GEAR_5A = 3,
            GEAR_Off = 4,
        }GearSelect;

        typedef enum {
            RATE_240SPS_12BIT = 00,
            RATE_60SPS_14BIT = 0x01<<2,
            RATE_15SPS_16BIT = 0x02<<2,
            RATE_3_75SPS_18BIT = 0x03<<2
        }ADCRate;

    private:
        ADCRate rate;
        GearSelect current_gear;
        uint8_t flag_print;
        uint8_t flag_autoSwitchGear;
        double rvoltage; //Sampling Resistor Voltage
        float rvoltage_estimate;
        kalman1_t kmfilter_rvoltage;

    public:
        
        Ammeter(void);
        void setRate(ADCRate Rate);
        ADCRate getRate(void);
        void dataReflash(void);

        void setGear(GearSelect Gear);
        GearSelect setGearAuto(void);
        GearSelect getGear(void);

        double getVoltage(void);
        double getCurrent(void);
        void printStart(void);
        void printStop(void);
        void autoModeStart(void);
        void autoModeStop(void);
};

#ifdef  __cplusplus
    extern "C" {
#endif
/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/

#ifdef __cplusplus
	}
#endif
#endif
